package org.zdlh.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.tcpimg.UIUtils;
import org.cbg.btn.TrslationBtn;
import org.come.until.CutButtonImage;
import org.zdlh.btn.ZdlhBtn;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;



public class ZdlhJpanel extends JPanel {

    final String[] automaticRefining = {"炼化", "炼器", "佩饰重铸", "星卡神通", "星卡五行", "觉醒洗练", "佩饰点粹"};

    public JLabel refining;

    public ZdlhOptionJpanel zdlhOptionJpanel;

    public TrslationBtn chooseDown;

    public Integer flag;

    //属性1-5
    public JTextField attribute1;
    public JTextField attribute1_1;


    public JTextField attribute2;
    public JTextField attribute2_1;

    public JTextField attribute3;
    public JTextField attribute3_1;

    public JTextField attribute4;
    public JTextField attribute4_1;

    public JTextField attribute5;
    public JTextField attribute5_1;

    //特技1-2
    public JTextField stunt1;
    public JTextField stunt1_1;
    public JTextField stunt2;
    public JTextField stunt2_1;

    public ZdlhBtn moyex;


    public ZdlhJpanel() {
        try {

            moyex = new ZdlhBtn("skin/8100226/newbutton/B20.png", 1, "开始", "开始",this);
            moyex.setBounds(150, 400, 59, 24);
            this.add(moyex);

            moyex = new ZdlhBtn("skin/8100226/newbutton/B20.png", 1, "停止", "停止",this);
            moyex.setBounds(250, 400, 59, 24);
            this.add(moyex);

            this.flag = 1;
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/background/gift-close-btn.png", 1, 691);
            offBtn.setBounds(423 - 28, 5, 19, 18);
            this.add(offBtn);
//            this.setBackground(UIUtils.COLOR_HURTB3);
            this.setPreferredSize(new Dimension(423, 475));
            this.setLayout(null);
            this.setOpaque(false);

            this.zdlhOptionJpanel = new ZdlhOptionJpanel(115, 90, automaticRefining);
            zdlhOptionJpanel.setBounds(50, 50, 115, 90);
            this.zdlhOptionJpanel.getJlist().addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(final MouseEvent e) {
                    final String getname = ZdlhJpanel.this.zdlhOptionJpanel.getJlist().getSelectedValue();
                    ZdlhJpanel.this.refining.setText(getname);
                    ZdlhJpanel.this.zdlhOptionJpanel.setVisible(false);
                    ZdlhJpanel.this.flag = 1;
                    ZdlhJpanel.this.clear();
                    if (ZdlhJpanel.this.refining.getText().equals("炼化")) {
                        ZdlhJpanel.this.refining.setText("炼化");
                    }
                    if (ZdlhJpanel.this.refining.getText().equals("炼器")) {
                        ZdlhJpanel.this.refining.setText("炼器");
                    }
                }
            });
            this.zdlhOptionJpanel.setVisible(false);
            this.add(this.zdlhOptionJpanel);


            (this.refining = new JLabel("炼化")).setForeground(Color.white);
            refining.setBounds(66, 30 , 96, 20);//选择后的分辨率显示位置
            this.refining.setFont(UIUtils.TEXT_FONT1);
            this.add(this.refining);

            (this.chooseDown = new TrslationBtn("", 1)).addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(final MouseEvent e) {
                    if (ZdlhJpanel.this.flag == 1) {
                        ZdlhJpanel.this.zdlhOptionJpanel.setVisible(true);
                        ZdlhJpanel.this.flag = 0;

                    } else {
                        ZdlhJpanel.this.zdlhOptionJpanel.setVisible(false);
                        ZdlhJpanel.this.flag = 1;
                    }
                }
            });
            chooseDown.setBounds(50, 30 , 115, 20);
            chooseDown.setIcons(CutButtonImage.cuts( "inkImg/newbackground/xl100.png"));
            this.add(this.chooseDown);

            attribute1 = new JTextField();
            setAttribute(attribute1, 122,80, 156);
            this.add(attribute1);

            attribute1_1 = new JTextField();
            setAttribute(attribute1_1, 288,80, 90);
            this.add(attribute1_1);

            attribute2 = new JTextField();
            setAttribute(attribute2, 122,80+27, 156);
            this.add(attribute2);

            attribute2_1 = new JTextField();
            setAttribute(attribute2_1, 288,80+27, 90);
            this.add(attribute2_1);

            attribute3 = new JTextField();
            setAttribute(attribute3, 122,80+27*2, 156);
            this.add(attribute3);

            attribute3_1 = new JTextField();
            setAttribute(attribute3_1, 288,80+27*2, 90);
            this.add(attribute3_1);

            attribute4 = new JTextField();
            setAttribute(attribute4, 122,80+27*3, 156);
            this.add(attribute4);

            attribute4_1 = new JTextField();
            setAttribute(attribute4_1, 288,80+27*3, 90);
            this.add(attribute4_1);

            attribute5 = new JTextField();
            setAttribute(attribute5, 122,80+27*4, 156);
            attribute5.setVisible(false);
            this.add(attribute5);

            attribute5_1 = new JTextField();
            setAttribute(attribute5_1, 288,80+27*4, 90);
            attribute5_1.setVisible(false);
            this.add(attribute5_1);

            //特技
            stunt1 = new JTextField();
            setAttribute(stunt1, 122,80+27*4, 156);
            this.add(stunt1);

            stunt1_1 = new JTextField();
            setAttribute(stunt1_1, 288,80+27*4, 90);
            this.add(stunt1_1);

            stunt2 = new JTextField();
            setAttribute(stunt2, 122,80+27*5, 156);
            this.add(stunt2);

            stunt2_1 = new JTextField();
            setAttribute(stunt2_1, 288,80+27*5, 90);
            this.add(stunt2_1);



        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void setAttribute(JTextField attribute1_1, int x, int y, int w) {
        attribute1_1.setCaretColor(Color.white);
        attribute1_1.setOpaque(false);
        attribute1_1.setBorder(BorderFactory.createEmptyBorder());
        attribute1_1.setForeground(Color.white);
        attribute1_1.setFont(UIUtils.TEXT_FONT1);
        attribute1_1.setBounds(x, y, w, 25);
    }

    private ImageIcon icon = CutButtonImage.getImage("inkImg/old/background/s285.png", 423, 475);
    private ImageIcon s286_lh = CutButtonImage.getImage("inkImg/old/background/s286-lh.png", 326, 157);
    private ImageIcon s286_lq = CutButtonImage.getImage("inkImg/old/background/s286-lq.png", 324, 132);


    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        g.drawImage(icon.getImage(), 0, 0, 423, 475, this);

        g.setFont(UIUtils.TEXT_FONT_17);
        g.setColor(Color.RED);
        g.drawString("请仔细检查是否有错别字",180,48);

        if(this.refining.getText().equals("炼化")){
            g.drawImage(s286_lh.getImage(), 50, 80, 326, 157, this);
        }else if(this.refining.getText().equals("炼器")){
            g.drawImage(s286_lq.getImage(), 50, 80, 324, 132, this);
        }

        g.setFont(UIUtils.TEXT_BOLD_FONT);
        g.setColor(Color.black);
        g.drawString("调出炼化面板点击开始即可开始自动炼化",50,300);
        g.drawString("如果需要锁定属性请在炼化面板进行锁定",50,330);
        g.drawString("特技属性只需填写特技名称",50,360);

    }

    private void clear(){
        this.attribute1.setText("");
        this.attribute1_1.setText("");

        this.attribute2.setText("");
        this.attribute2_1.setText("");

        this.attribute3.setText("");
        this.attribute3_1.setText("");

        this.attribute4.setText("");
        this.attribute4_1.setText("");

        this.attribute5.setText("");
        this.attribute5_1.setText("");

        this.stunt1.setText("");
        this.stunt1_1.setText("");

        this.stunt2.setText("");
        this.stunt2_1.setText("");
    }


}
